package net.htjs.juc.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

//@Slf4j(topic = "c.Test1")
@Slf4j
public class ThreadState2 {

    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            log.info("running");
        }, "t1");

        Thread t2 = new Thread(()->{
            while(true) {

            }
        }, "t2");
        t2.start();
        Thread t3 = new Thread(()->{
            log.info("running");
        }, "t3");
        t3.start();

        Thread t4 = new Thread(()->{
            synchronized (ThreadState2.class) {
                try {
                    //TIMED_WAITING
                    TimeUnit.SECONDS.sleep(100000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t4");
        t4.start();

        Thread t5 = new Thread(()->{
            try {
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t5");
        t5.start();

        Thread t6 = new Thread(()->{
            synchronized (ThreadState2.class) {
                try {
                    //TIMED_WAITING
                    TimeUnit.SECONDS.sleep(100000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t6");
        t6.start();

        try {
            TimeUnit.MILLISECONDS.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.info("t1 state:{}", t1.getState());
        log.info("t2 state:{}", t2.getState());
        log.info("t3 state:{}", t3.getState());
        log.info("t4 state:{}", t4.getState());
        log.info("t5 state:{}", t5.getState());
        log.info("t6 state:{}", t6.getState());


    }



}
